<template>
	<view class="container">
		<view class="wrapper">
			<view class="venueForm">
				<view >
					<view class="form-row">
						<view class="ftitle">旧的密码</view>
						<input class="fvalue"  v-model="form.oldPassword" type="password" placeholder="输入登录密码"  />
					</view>
				</view>
				<view class="height30"></view>
				<view >
					<view class="form-row">
						<view class="ftitle">新的密码</view>
						<input class="fvalue"  v-model="form.password" type="password" placeholder="输入登录密码"  />
					</view>
				</view>
				<view class="height30"></view>
				<view >
					<view class="form-row">
						<view class="ftitle">确认密码</view>
						<input class="fvalue"  v-model="form.passwordConfirm" type="password" placeholder="输入登录密码"  />
					</view>
				</view>
			</view>
			<view class="height30"></view>
			<view style="padding: 20rpx 30rpx;">
				<button class="submitBtn" @click="formSubmitBtn">提 交</button>
			</view>
		</view>
	</view>
</template>

<script>
	import md5 from '@/utils/md5.js';
	export default {
		data() {
			return {
				//重置申请表单
				form: {
					//旧密码
					oldPassword: '',
					//新密码
					password: '',
					//新密码确认
					passwordConfirm: ''
				}
			}
		},
		methods: {
			
			//提交注册申请
			formSubmitBtn(){
				
				if(!this.form.oldPassword){
					uni.$u.toast("请输入旧的密码")
					return ;
				}
				if(!this.form.password){
					uni.$u.toast("请输入新的登录密码")
					return ;
				}
				if(!this.form.passwordConfirm){
					uni.$u.toast("请再一次输入新的登录密码")
					return ;
				}
				if(this.form.password != this.form.passwordConfirm){
					uni.$u.toast("两次密码输入不一致，请确认新的登录密码")
					return ;
				}
				
				
				
				let that=this
				uni.showModal({
					title: '提示',
					content: '确认是否提交修改密码操作?',
					success: function(res) {
						if (res.confirm) {
							that.updatePassWord();
						}
					}
				});
				
			},
			//提交申请
			updatePassWord(){
				const params = {};
				//商家端用户ID
				params.bladeUserId = uni.getStorageSync('userId');
				//旧密码
				params.oldPassword = md5.hex_md5_32(this.form.oldPassword);
				//新密码
				params.newPassword = md5.hex_md5_32(this.form.password);
				
				uni.showLoading({
					title: '提交中',
					mask: true
				})
				var urlParams = '?bladeUserId='+params.bladeUserId+'&oldPassword='+params.oldPassword+'&newPassword='+params.newPassword;
				//后端接收为param
				this.$request({
					url: '/blade-merchant-app/merchant-app/user/update-password'+urlParams,
					type: 'POST',
					data: {}
				}).then(res => {
					uni.hideLoading();
					if (res?.code === 200) {
						
						uni.showModal({
						   title: '操作成功',
						   content: '您的密码已修改成功，下次登录请按照新的密码输入',
						   showCancel: false,
						   success: function (res) {
							   if (res.confirm) {
								   uni.navigateBack()
							   }
						   }
						});
						
					} else {
						uni.$u.toast(res.msg);
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	
	page {
		height: 100%;
		overflow: hidden;
		letter-spacing: 1rpx;
		background: #f1f1f1;
	
		.container {
			
	
			.wrapper {
				width: 100%;
				
				
				.venueForm {
					background-color: #ffffff;
					padding: 30rpx;
					
					.form-row {
						border-radius: 8rpx;display: flex;border: 1px solid #c3c3c3;justify-content: center;align-items: center; 
						
						.ftitle {
							text-align: center;
							font-size: 30rpx;
							width: 180rpx;
							display: inline-table;
							color: #333333;
							padding:0rpx 10rpx;
						}
						.fvalue {
							height: 90rpx;width: 100%;font-size: 32rpx;
						}
					
					}
					
				}
				
			}
		}
	}		
		
	.height30 {
		height: 30rpx;
	}
	.submitBtn {
		height: 90rpx;background-color: #0544ab;color: #ffffff;line-height: 90rpx;font-size: 32rpx;
	}	
 

</style>
